import axios from "axios";
import store from "../store/index";

/**
 * 公共请求
 * @param {*} url
 * @param {*} data
 */
export const _axios = (url, data, method) => {
  // console.log(store,'++')
  let paramsInit = {
    ...data
  };
  if (method == "post" || method == "put" || method == "delete") {
    return new Promise((resolve, reject) => {
      axios({
        method,
        url,
        data: paramsInit
      })
        .then(res => {
          resolve(res.data);
        })
        .catch(err => {
          reject(err);
        });
    });
  } else if (method == "get") {
    return new Promise((resolve, reject) => {
      axios({
        url,
        method,
        params: paramsInit,
      })
        .then((res) => {
          resolve(res.data);
        })
        .catch((err) => {
          reject(err);
        });
    });
  }
};
